﻿using System.Collections.Generic;

namespace E.Story
{
    public static class DataUtility
    {
        /// <summary>
        /// 克隆条件数据列表
        /// </summary>
        /// <param name="oldDatas">条件数据列表</param>
        /// <returns>条件数据列表</returns>
        public static List<ConditionData> CloneConditionDatas(List<ConditionData> oldDatas)
        {
            List<ConditionData> newDatas = new();
            foreach (ConditionData data in oldDatas)
            {
                ConditionData newData = new()
                {
                    VarIndex =  data.VarIndex,
                    Value = data.Value,
                    Compare = data.Compare,
                };
                newDatas.Add(newData);
            }

            return newDatas;
        }

        /// <summary>
        /// 克隆选择数据列表
        /// </summary>
        /// <param name="oldDatas">选择数据列表</param>
        /// <returns>选择数据列表</returns>
        public static List<ChoiceData> CloneChoiceDatas(List<ChoiceData> oldDatas)
        {
            List<ChoiceData> newDatas = new();
            foreach (ChoiceData data in oldDatas)
            {
                List<ConditionData> conditionDatas = CloneConditionDatas(data.Conditions);
                ChoiceData newData = new(data.Text, data.NextNodeID, data.DetectMode, conditionDatas);
                newDatas.Add(newData);
            }

            return newDatas;
        }

        /// <summary>
        /// 克隆句子数据列表
        /// </summary>
        /// <param name="oldDatas">句子数据列表</param>
        /// <returns>句子数据列表</returns>
        public static List<SentenceData> CloneSentenceDatas(List<SentenceData> oldDatas)
        {
            if (oldDatas == null)
            {
                return null;
            }

            List<SentenceData> newDatas = new();
            foreach (SentenceData data in oldDatas)
            {
                SentenceData newData = new(data.Text);
                newDatas.Add(newData);
            }

            return newDatas;
        }

        /// <summary>
        /// 克隆变量数据列表
        /// </summary>
        /// <param name="editVarDatas">变量数据列表</param>
        /// <returns>变量数据列表</returns>
        public static List<VarData> CloneVarDatas(List<VarData> oldDatas)
        {
            if (oldDatas == null)
            {
                return null;
            }

            List<VarData> newDatas = new();
            foreach (VarData data in oldDatas)
            {
                VarData newData = new(data.Key, data.Value);
                newDatas.Add(newData);
            }

            return newDatas;
        }

        /// <summary>
        /// 克隆编辑变量数据列表
        /// </summary>
        /// <param name="oldDatas">编辑变量数据列表</param>
        /// <returns>编辑变量数据列表</returns>
        public static List<EditVarData> CloneEditVarDatas(List<EditVarData> oldDatas)
        {
            if (oldDatas == null)
            {
                return null;
            }

            List<EditVarData> newDatas = new();
            foreach (EditVarData data in oldDatas)
            {
                EditVarData newData = new()
                {
                    VarIndex = data.VarIndex,
                    Value = data.Value,
                    Operation = data.Operation,
                };
                newDatas.Add(newData);
            }

            return newDatas;
        }
    }
}